def find_last_reporter(m, n):  
    if n % 7 == 0:  
        n -= 1  
      
    current_person = 0  
    current_number = 1  
      
    while current_number <= n:  
        if current_number % 7 == 0:  
            current_number += 1  
        else:  
            current_number += 1
            current_person = (current_person % m) + 1
      
    return current_person  
  
m = int(input())  
n = int(input())  
  
last_reporter = find_last_reporter(m, n)  
print(last_reporter)